package org.gdufe.comment.controller;

import org.gdufe.comment.service.CommentService;
import org.gdufe.comment.service.CountPointScheduleService;
import org.gdufe.comment.service.impl.CountPointSechduleServiceImpl;
import org.gdufe.pojos.dto.CreateCommentDto;
import org.gdufe.pojos.dto.PageParams;
import org.gdufe.pojos.vo.PageResponseResult;
import org.gdufe.pojos.vo.R;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.LinkedList;

@RestController
@RequestMapping("/comment")

public class CommentController {

    @Autowired
    private CommentService commentService;

    @Autowired
    private CountPointScheduleService countPointScheduleService;


    //分页查找评论
    @GetMapping("/querry")
    public PageResponseResult querry(PageParams pageParams,Integer bId){
        return commentService.querry(pageParams,bId);
    }

    //添加评论
    @PostMapping("/createComment")
    public R createComment(@RequestBody CreateCommentDto createCommentDto){
        Object principalObj = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String username = principalObj.toString();
        return commentService.createComment(createCommentDto,username);
    }

    //前端不用写
    @GetMapping("/countPoint")
    public void testCount(){
        countPointScheduleService.countPoint();
    }
}
